package wyu.controller;

import com.dto.Result;
import com.entity.User;
import com.entity.UserBarNum;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import wyu.service.UserBarService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/user_bar")
public class UserBarController {
    @Resource
    UserBarService userBarService;
    /*获取对应贴吧id的关注人数 */
    @GetMapping("/getCount")
    public int getUserBarNumCount(@RequestParam("barId")int barId){
        return userBarService.getUserBarCount(barId);
    }
    /*查询当前登录用户是否关注了当前贴吧*/
    @GetMapping("/getUserBarRelevancy")
    public boolean getUserBarRelevancy(@RequestParam("uName")String uName,
                                       @RequestParam("barId")int barId){
        Integer count = userBarService.query().eq("USER_UNAME", uName)
                .eq("BAR_ID", barId).count();
        if (count>0){
            return true;
        }
        return false;
    }
    /*查询当前登录用户关注的贴吧的id列表*/
    @GetMapping("/getUserBarList")
    public List<Integer> getUserBarList(@RequestParam("uName")String uname){

        return userBarService.getUserBarList(uname);
    }
    /*新增一条用户关注贴吧记录*/
    @GetMapping("/joinBar")
    public boolean joinBar(@RequestParam("barId")int barId,String uName){
        return userBarService.joinBar(barId,uName);
    }
    /*删除一条用户关注贴吧记录*/
    @GetMapping("/exitBar")
    public boolean exitBar(@RequestParam("barId")int barId,String uName){
        return userBarService.exitBar(barId,uName);
    }
}
